/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager.search;

import br.com.deployment.daoImpl.CityDAOImpl;
import br.com.deployment.daoImpl.OrganDAOImpl;
import br.com.deployment.entities.City;
import br.com.deployment.entities.Organ;
import br.com.deployment.utils.Msg;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author luciano
 */
@ManagedBean
@SessionScoped
public class ManagerEditOrgan {
    
    @EJB
    OrganDAOImpl organService;
    
    private Organ organ;
    private City city;
    
    @EJB
    CityDAOImpl cityService;

    public ManagerEditOrgan() {
        this.city = new City();
    }
    
    public void update(){
        this.organ.setCity(this.city);
        organService.update(organ);
        Msg.messagemInfo("Orgão Atualizado com Sucesso.");
        this.city = cityService.find(this.city.getId());
    }
    
     // Seleciona o Objeto Orgão Redireciona para a página
    public void redirect(String string, Organ o) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            this.organ = o;
            this.city = o.getCity();
            context.getExternalContext().redirect(string);
        } catch (IOException ex) {
            Logger.getLogger(ManagerEditExecutor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Organ getOrgan() {
        return organ;
    }

    public void setOrgan(Organ organ) {
        this.organ = organ;
    }

   
    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }
    
    
    
}
